/********************************************************************************
 * @Author: Zhenzhou Liu
 * @Date: 2024-11-21
 * @Description: Cg分治练习之最大子数组
 *******************************************************************************/
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <climits>

using namespace std;

pair<pair<int, int>, int> crossingSubArray(const vector<int>& nums, int left, int midden, int right)
{
    int sLeft = -INT_MAX, sRight = -INT_MAX, sum = 0, leftIndex = midden, rightIndex = midden + 1;
    for (int i = midden; i >= left; --i)
    {
        sum += nums[i];
        if (sum > sLeft)
        {
            sLeft = sum;
            leftIndex = i;
        }
    }
    sum = 0;
    for (int i = midden + 1; i <= right; ++i)
    {
        sum += nums[i];
        if (sum > sRight)
        {
            sRight = sum;
            rightIndex = i;
        }
    }
    return {{leftIndex, rightIndex}, sLeft + sRight};
}

pair<pair<int, int>, int> maxSubArray(const vector<int>& nums, int left, int right)
{
    if (left == right)
        return {{left, right}, nums[left]};
    int midden = left + ((right - left) >> 1);
    auto s1 = maxSubArray(nums, left, midden);
    auto s2 = maxSubArray(nums, midden + 1, right);
    auto s3 = crossingSubArray(nums, left, midden, right);
    return max({s1, s2, s3}, [](const pair<pair<int, int>, int>& a, const pair<pair<int, int>, int>& b)
    {
        return a.second < b.second;
    });
}

int main()
{
    string input;
    getline(cin, input);
    stringstream ss(input);
    int temp;
    vector<int> nums;
    while (ss >> temp)
    {
        if (ss.peek() == ',')
            ss.ignore();
        nums.push_back(temp);
    }
    auto res = maxSubArray(nums, 0, nums.size() - 1);
    cout << "X[" << res.first.first << "," << res.first.second << "]=" << res.second;
    return 0;
}